<template>
  <div class="jobDetail">
    <a-descriptions title="Offer-描述">
      <a-descriptions-item label="Offer状态">{{ offerInfo.offerStatus }}</a-descriptions-item>
      <a-descriptions-item label="Offer-截止时间">{{formatInterviewDate(offerInfo.offerExpirationDate)}}</a-descriptions-item>
      <!--      //占位-->
      <a-descriptions-item :span="3"></a-descriptions-item>
      <a-descriptions-item :span="3" label="Offer-补充信息">
        <span v-html="truncateText(offerInfo.offerSupplementaryInformation)"></span>
      </a-descriptions-item>
    </a-descriptions>
  </div>


  <div class="jobDetail">
    <a-descriptions title="职位-描述">
      <a-descriptions-item label="职位标题">{{ formState.job_title }}</a-descriptions-item>
      <a-descriptions-item label="职位地点">{{ formState.job_location }}</a-descriptions-item>
      <a-descriptions-item label="薪资范围">{{ formState.job_salary }}</a-descriptions-item>
      <a-descriptions-item label="学历要求">{{ formState.job_education_requirement }}</a-descriptions-item>
      <a-descriptions-item label="专业要求">{{ formState.job_major_requirement }}</a-descriptions-item>
      <a-descriptions-item label="岗位联系方式">{{ formState.job_contactinfo }}</a-descriptions-item>
      <a-descriptions-item label="所属行业">{{ formState.job_industry }}</a-descriptions-item>

      <!--      //占位-->
      <a-descriptions-item :span="3"></a-descriptions-item>
      <a-descriptions-item :span="3" label="技能要求">
        <span v-html="truncateText(formState.job_skill_requirement)"></span>
      </a-descriptions-item>
      <a-descriptions-item :span="3" label="岗位福利">
        <span v-html="truncateText(formState.job_benefits)"></span>
      </a-descriptions-item>
      <a-descriptions-item :span="3" label="岗位表述">
        <span v-html="truncateText(formState.job_description)"></span>
      </a-descriptions-item>
    </a-descriptions>


  </div>

  <div class="jobDetail">

    <a-row>
      <a-col :span="20">
        <a-descriptions title="公司-详情">
          <a-descriptions-item label="公司名称">{{ formState.enterprise_name }}</a-descriptions-item>
          <a-descriptions-item label="公司行业">{{ formState.enterprise_industry }}</a-descriptions-item>
          <a-descriptions-item label="公司规模">{{ formState.enterprise_size }}</a-descriptions-item>
          <a-descriptions-item label="公司成立时间">{{ formattedFoundationDate }}</a-descriptions-item>
          <a-descriptions-item label="公司类型">{{ formState.enterprise_type }}</a-descriptions-item>
          <a-descriptions-item label="公司邮箱">{{ formState.enterprise_email }}</a-descriptions-item>
          <a-descriptions-item :span="3" label="公司官网：">{{ formState.enterprise_website }}</a-descriptions-item>
          <a-descriptions-item :span="3" label="公司社交媒体连接：">{{ formState.enterprise_social_media_links }}
          </a-descriptions-item>
          <a-descriptions-item :span="3" label="公司地点">{{ formState.enterprise_address }}</a-descriptions-item>
          <a-descriptions-item :span="3" label="公司简介">
            <span v-html="truncateText(formState.enterprise_profile)"></span>
          </a-descriptions-item>
        </a-descriptions>
      </a-col>
      <a-col :span="4">
        <a-image
            :height="200"
            :src="'http://localhost:8080/file/download?name='+formState.enterprise_logo_url"
            :width="200"
        />
      </a-col>

    </a-row>
  </div>

</template>

<script setup>


import {computed, onMounted, reactive, ref} from "vue";
import {useRoute, useRouter} from "vue-router";
import {queryJobDetailByJobIdAPI} from "@/apis/job.js";
import {useUserStore} from "@/stores/user.js";
import {message} from "ant-design-vue";
import {queryOfferByIdAPI, updateOfferByIdAPI} from "@/apis/offer.js";

// 新增方法用于将回车替换微br空格替换微&nbsp
const truncateText = (text) => {
  return text.replace(/\n/g, '<br>').replace(/ /g, '&nbsp;');
};


const route = useRoute()
//定义数据
const formState = reactive({
  job_id: '',
  job_title: '',
  job_location: '',
  job_salary: '',
  job_education_requirement: '',
  job_major_requirement: '',
  job_experience_requirement: '',
  job_skill_requirement: '',
  job_description: '',
  job_benefits: '',
  job_publish_date: '',
  job_deadline: '',
  job_contactinfo: '',
  job_status: undefined,
  job_industry: '',
  job_company_id: '',


  enterprise_name: '',
  enterprise_certification_status: '',
  enterprise_logo_url: '',
  enterprise_profile: '',
  enterprise_industry: '',
  enterprise_size: '',
  enterprise_foundation_date: '',
  enterprise_type: '',
  enterprise_address: '',
  enterprise_email: '',
  enterprise_website: '',
  enterprise_social_media_links: '',
  account: '',
  userRole: '',
  enterpriseId: '',
});
//定义Offer数据
const offerInfo = reactive({
  offerId: '',
  offerStatus: '',
  offerSupplementaryInformation: '',
  offerExpirationDate: '',
})
//查看数据，该岗位是否收藏，是否投递。
const isCollect = ref(false);
const isAcceptOffer = ref(false);
const isRefuseOffer = ref(false);
//获取数据
const useStore = useUserStore();
const getData = async (jobId,offerId) => {
  //查询Offer信息
  const res1 = await queryOfferByIdAPI(offerId)
  offerInfo.offerId = res1.data.data.offerId;
  offerInfo.offerStatus = res1.data.data.offerStatus;
  offerInfo.offerSupplementaryInformation = res1.data.data.offerSupplementaryInformation;
  offerInfo.offerExpirationDate = res1.data.data.offerExpirationDate;
  if(res1.data.data.offerStatus==='已接受'){
    isAcceptOffer.value=true;
  }else if(res1.data.data.offerStatus==='已拒绝'){
    isRefuseOffer.value=true;
  }

  //查询其他信息
  const res = await queryJobDetailByJobIdAPI(jobId)
  formState.job_id = res.data.data.jobVO.jobId;
  formState.job_title = res.data.data.jobVO.jobTitle;
  formState.job_location = res.data.data.jobVO.jobLocation;
  formState.job_salary = res.data.data.jobVO.jobSalary;
  formState.job_education_requirement = res.data.data.jobVO.jobEducationRequirement;
  formState.job_major_requirement = res.data.data.jobVO.jobMajorRequirement;
  formState.job_experience_requirement = res.data.data.jobVO.jobExperienceRequirement;
  formState.job_skill_requirement = res.data.data.jobVO.jobSkillRequirement;
  formState.job_description = res.data.data.jobVO.jobDescription;
  formState.job_benefits = res.data.data.jobVO.jobBenefits;
  formState.job_publish_date = res.data.data.jobVO.jobPublishDate;
  formState.job_deadline = res.data.data.jobVO.jobDeadline;
  formState.job_contactinfo = res.data.data.jobVO.jobContactInfo;
  formState.job_status = res.data.data.jobVO.jobStatus;
  formState.job_industry = res.data.data.jobVO.jobIndustry;
  formState.job_company_id = res.data.data.jobVO.jobCompanyId;

  formState.enterprise_name = res.data.data.enterpriseVO.enterpriseName;
  formState.enterprise_certification_status = res.data.data.enterpriseVO.enterpriseCertificationStatus;
  formState.enterprise_logo_url = res.data.data.enterpriseVO.enterpriseLogoUrl;
  formState.enterprise_profile = res.data.data.enterpriseVO.enterpriseProfile;
  formState.enterprise_industry = res.data.data.enterpriseVO.enterpriseIndustry;
  formState.enterprise_size = res.data.data.enterpriseVO.enterpriseSize;
  formState.enterprise_foundation_date = res.data.data.enterpriseVO.enterpriseFoundationDate;
  formState.enterprise_type = res.data.data.enterpriseVO.enterpriseType;
  formState.enterprise_address = res.data.data.enterpriseVO.enterpriseAddress;
  formState.enterprise_email = res.data.data.enterpriseVO.enterpriseEmail;
  formState.enterprise_website = res.data.data.enterpriseVO.enterpriseWebsite;
  formState.enterprise_social_media_links = res.data.data.enterpriseVO.enterpriseSocialMediaLinks;

}

//时间格式处理
const formattedFoundationDate = computed(() => {
  const date = new Date(formState.enterprise_foundation_date);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以需要加1
  const day = String(date.getDate()).padStart(2, '0');
  // const hours = String(date.getHours()).padStart(2, '0');
  // const minutes = String(date.getMinutes()).padStart(2, '0');
  // const seconds = String(date.getSeconds()).padStart(2, '0');
  // return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  return `${year}-${month}-${day}`;
});


//接收路由参数
const jobId = ref();
const offerId = ref();
// 生命周期
onMounted(() => {
  jobId.value = route.params.jobId;
  offerId.value = route.params.offerId;
  getData(jobId.value,offerId.value)
});
//时间处理函数
const formatInterviewDate = (dateString) => {
  const date = new Date(dateString);

  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
  const day = String(date.getDate()).padStart(2, '0');
  const hours = String(date.getHours()).padStart(2, '0');
  const minutes = String(date.getMinutes()).padStart(2, '0');

  return `${year}-${month}-${day} ${hours}:${minutes}`;
};

</script>
<style scoped>
.jobDetail {
  margin: 20px;
  padding: 20px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1), 0 6px 20px rgba(0, 0, 0, 0.1);
  border-radius: 10px; /* 你可以调整这个值来改变圆角的大小 */
}


</style>
